/*
 * @Author: silence
 * @Date: 2023-10-11 16:53:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-10-19 13:06:38
 * @Description: 
 */
import 'package:ems_neutral_app/api/ApiUtils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:gif_view/gif_view.dart';

import '../../api/request/UserRequest.dart';
import '../../base/SilScaffold.dart';
import '../../bloc/userbloc/user_bloc.dart';
import '../../utils/eventBus/eventBus.dart';
import '../../utils/string/StringConstant.dart';
import '../Mine/Language/LanguageController.dart';

class LaunchAnimationPage extends StatefulWidget {
  const LaunchAnimationPage({super.key});

  @override
  State<LaunchAnimationPage> createState() => _LaunchAnimationPageState();
}

class _LaunchAnimationPageState extends State<LaunchAnimationPage> {
  GifController? _gifController;

  /// 当前语言
  LanguageController _languageController =
      Get.put<LanguageController>(LanguageController());
  bool _isPromptEnglish = true;

  @override
  void initState() {
    super.initState();
    _isPromptEnglish = _languageController.isPromptEnglish();

    /// 控制启动图
    _gifController = GifController(
      loop: false,
      onFinish: launchHandler,
    );
  }

  /// 启动处理
  launchHandler() {
    /// 用户未登录，直接返回
    bus.emit(StringConstant.LaunchAnimationFinished); // 启动动画结束了

    // bool isLogin = UserBlocTool.isLogin();
    // if (isLogin == false) {
    //   /// 用户未登录，直接返回
    //   bus.emit(StringConstant.LaunchAnimationFinished); // 启动动画结束了
    //   return;
    // }

    // /// 如果用户已经登录，处理用户是否有添加电站
    // apiShow(context, api: api_userInfo_info(), success: (p0) {
    //   bus.emit(StringConstant.LaunchAnimationFinished); // 启动动画结束了
    // }, failure: (p0) {
    //   bus.emit(StringConstant.LaunchAnimationFinished); // 启动动画结束了
    // }, showLoading: false);
  }

  @override
  Widget build(BuildContext context) {
    return SilScaffold(
        sideMargin: 0,
        navBarHide: true,
        stateBarHide: true,
        body: mainWidget());
  }

  mainWidget() {
    return GifView.asset(
      _isPromptEnglish ? 'imgs/common/kaijiEN.gif' : 'imgs/common/kaiji.gif',
      controller: _gifController,
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      repeat: ImageRepeat.noRepeat,
      fit: BoxFit.fill,
    );
  }
}
